#include <iostream>
#include <memory>
#include <functional>
#include "TcpServer.hpp"  //处理IO
#include "Calculator.hpp" //处理业务
#include "log.hpp"
Calculator calculator;
// for debug
void DefaultOnMessage(std::shared_ptr<Connection> connection_ptr)
{
    // 对报文进行处理
    std::cout << "上层得到了数据: " << connection_ptr->InBuffer() << std::endl;
    std::string response_ptr = calculator.Handler(connection_ptr->InBuffer());
    if (response_ptr.empty())
        return;
    log(Debug, "%s", response_ptr.c_str());
    // response_ptr 发送出去
    connection_ptr->AppendOutBuffer(response_ptr);
    // connection_ptr->_send_cb(connection_ptr);
    connection_ptr->_tcp_server_ptr->Sender(connection_ptr);
}
int main()
{
    std::unique_ptr<TcpServer> epoll_svr(new TcpServer(8080, DefaultOnMessage));
    epoll_svr->Init();
    epoll_svr->Loop();
    return 0;
}
